package indi.jp.project.business.jingying.controller;

import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.core.util.SimpleEntityUtil;
import indi.jp.project.business.jingying.entity.Supplies;
import indi.jp.project.business.jingying.pojo.query.SuppliesQuery;
import indi.jp.project.business.jingying.service.SuppliesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 经营用品审批Controller
 *
 * @author jiangping
 * @date 2022/5/7
 */
@RestController
@RequestMapping("/jingying/supplies")
public class SuppliesController {

    @Resource
    private SuppliesService suppliesService;

    @GetMapping("/grid")
    public JsonResult queryGrid(SuppliesQuery query, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        query.setLander(account);
        return suppliesService.queryGrid(query);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody Supplies supplies, HttpServletRequest request) throws Exception {
        SimpleEntityUtil<Supplies> simpleEntityUtil = new SimpleEntityUtil<>();
        supplies = simpleEntityUtil.setBaseEntity(supplies, request);
        return suppliesService.save(supplies);
    }

    @PostMapping("/deleteById")
    public JsonResult deleteById(@RequestParam String id) throws Exception {
        return suppliesService.deleteById(id);
    }

    @GetMapping("/findById")
    public JsonResult findById(@RequestParam @Valid String id) throws Exception {
        return suppliesService.findById(id);
    }
}
